using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;

namespace HeThongDAO
{
    public class PhanLoaiTaiKhoanDAO
    {
        public static DataTable LayDanhSachLoaiTaiKhoan()
        {
            string sql = "Select * From PHAN_LOAI_TAI_KHOAN";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        public static bool ThemLoaiTaiKhoan(PhanLoaiTaiKhoanDTO loaiTKDTO)
        {
            try
            {
                string sql = "INSERT INTO PHAN_LOAI_TAI_KHOAN(TenTaiKhoan, MieuTa, PhieuNhapSach, HoaDonBanSach, PhieuThuTien, BaoCao, QuyDinh) ";
                sql += "VALUES('" + loaiTKDTO.TenTaiKhoan + "','";
                sql += loaiTKDTO.MieuTa + "',";
                sql += loaiTKDTO.PhieuNhapSach + ",";
                sql += loaiTKDTO.HoaDonBanSach + ",";
                sql += loaiTKDTO.PhieuThuTien + ",";
                sql += loaiTKDTO.BaoCao + ",";
                sql += loaiTKDTO.QuiDinh + ")";

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool CapNhatLoaiTaiKhoan(PhanLoaiTaiKhoanDTO loaiTKDTO)
        {
            try
            {
                string sql = "UPDATE PHAN_LOAI_TAI_KHOAN SET ";
                sql += "TenTaiKhoan = '" + loaiTKDTO.TenTaiKhoan + "', ";
                sql += "MieuTa = '" + loaiTKDTO.MieuTa + "', ";
                sql += "PhieuNhapSach = " + loaiTKDTO.PhieuNhapSach + ", ";
                sql += "HoaDonBanSach = " + loaiTKDTO.HoaDonBanSach + ", ";
                sql += "PhieuThuTien = " + loaiTKDTO.PhieuThuTien + ", ";
                sql += "BaoCao = " + loaiTKDTO.BaoCao + ", ";
                sql += "QuyDinh = " + loaiTKDTO.QuiDinh;
                sql += " WHERE MaLoaiTaiKhoan = " + loaiTKDTO.MaLoaiTaiKhoan;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool XoaLoaiTaiKhoan(PhanLoaiTaiKhoanDTO loaiTKDTO)
        {
            try
            {
                string sql = "DELETE FROM PHAN_LOAI_TAI_KHOAN ";
                sql += "WHERE MaLoaiTaiKhoan = " + loaiTKDTO.MaLoaiTaiKhoan;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
